package com.heking.widgetlib;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.zhoug.common.base.AbsActivity;
import com.zhoug.widget.EmptyView;
import com.zhoug.widget.TopView;
import com.zhoug.widget.round.RoundButton;

import androidx.annotation.Nullable;

/**
 *空界面
 * @Author 35574
 * @Date 2020/7/2
 * @Description
 */
public class EmptyViewActivity extends AbsActivity {
    private Button mBtn1;
    private EmptyView mEmptyView;
    private LinearLayout mContent;
    private TopView mTopView;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_empty_view;
    }

    @Override
    protected void findViews() {
        mBtn1 = findViewById(R.id.btn1);
        mEmptyView = findViewById(R.id.emptyView);
        mContent = findViewById(R.id.content);
        mTopView = findViewById(R.id.topView);
    }

    @Override
    protected void addListener() {
        mBtn1.setOnClickListener(v->{
            toast("btn1");
            refresh();
        });
    }

    @Override
    protected void initView() {
        mTopView.setTitle("我是标题zxczxczxczx题题题题题题题");
        mTopView.addBackImage().setOnClickListener(v->finish());
        mTopView.addRightTextView("确定",R.id.textView2);

    }

    @Override
    protected void onCreateFinish(@Nullable Bundle savedInstanceState) {
        refresh();
    }
    private  volatile int i=0;
    private void refresh(){
        mEmptyView.show(true);
        mContent.setVisibility(View.GONE);
        new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            i++;
            if(i==6){
                i=1;
            }
            runOnUiThread(this::onData);


        }).start();
    }

    private void onData(){
        switch (i){
            case 4:
                mEmptyView.hide();
                mContent.setVisibility(View.VISIBLE);
                break;
            case 2:
                mEmptyView.show("服务器连接失败",null);
                break;
            case 3:
                mEmptyView.show("服务器连接失败","请检查网络");
                break;
            case 1:
                mEmptyView.show("网络连接失败", "请检查网络是否开启", "重试", v -> refresh());
                break;
            case 5:
                mEmptyView.show(false);
                break;
        }
    }
}
